<template>
  <div>
    <f-table ref="table" rowKey="orderDetailsId" size="small" :scroll="{x:true}"  :columns="columns" handler="noCbReturnPageListHandler" :showMultipleBtn="false" :multiple="multiple" :operator="operator"  :params="queryParam" :api="api.bod">
      <span slot="ownerState" slot-scope="text, record, index">
            <a-tag color="#108ee9" v-if="text==0">否</a-tag>
            <a-tag color="#f50" v-if="text==1">是</a-tag>
       </span>
      <span slot="supplierBondType" slot-scope="text, record, index">
            <a-tag color="#2db7f5" v-if="text==0">不垫付</a-tag>
            <a-tag color="purple" v-if="text==1">底价</a-tag>
            <a-tag color="purple" v-if="text==2">底价+税金</a-tag>
            <a-tag color="purple" v-if="text==3">税金</a-tag>
            <a-tag color="purple" v-if="text==6">底价/2+税金</a-tag>
            <a-tag color="purple" v-if="text==5">全额垫付</a-tag>
            <a-tag color="purple" v-if="text==8">销售金额*费率</a-tag>
        </span>
      <span slot="customBondType" slot-scope="text, record, index">
           <a-tag color="#2db7f5" v-if="text==0">全款</a-tag>
            <a-tag color="purple" v-if="text==1">底价</a-tag>
            <a-tag color="purple" v-if="text==2">底价+税金</a-tag>
            <a-tag color="purple" v-if="text==6">底价/2+税金</a-tag>
            <a-tag color="purple" v-if="text==3">税金</a-tag>
            <a-tag color="purple" v-if="text==5">全额资信</a-tag>
            <a-tag color="purple" v-if="text==7">预收款</a-tag>
        </span>
      <span slot="action" slot-scope="text, record">
          <template>
             <a href='javascript:;'  @click='settleHandler(record)'>退款</a>
              <a-divider type='vertical'  />
             <a @click="$refs.orderInfoDrawer.showDrawer(record)" >查看</a>
          </template>
        </span>
    </f-table>
    <cbreturn-drawer ref="cbreturnDrawer" @success="onLoad"></cbreturn-drawer>
    <order-info-drawer ref="orderInfoDrawer"></order-info-drawer>
  </div>
</template>
<script>
  import api from './../js/api'
  import CbreturnDrawer from './cbreturn_drawer'
  import OrderInfoDrawer from '@/views/module/business/order/order_info_drawer'

  export default {
    name: 'CbreturnNo',
    components: { OrderInfoDrawer, CbreturnDrawer },
    data() {
      let me = this
      //操作按钮
      let operator = []
      let companyId = this.$store.getters.companyId
      operator.push({
        name: "批量退款",
        icon: "transaction",
        that: this,
        handler: function(table, that) {
          let selectIds = table.selectedRowKeys
          if (selectIds.length > 0) {
            let customBond = table.getSelectedTotal("customBond")
            let customOverBond = table.getSelectedTotal("customOverBond")
            let totalAmount=Number(customBond)+Number(customOverBond);
            me.$refs["cbreturnDrawer"].showDrawer({
              customBond:totalAmount,
              selectIds:  selectIds.join(","),
              deptId: me.deptId
            }, "form1")

          } else {
            that.$message.error("请选择部门")
          }
        }
      })
      return {
        api: Object.assign(api, this.api),
        multiple:true,
        deptId:'',
        //列表初始化查询参数
        queryParam: {
          auth:1
        },
        // 表头
        columns: [
          {
            title: "序号",
            width: "60px",
            align: "left",
            fixed: "left",
            customRender: (text, record, index) => index + 1
          },{
            title: "操作",
            align: "left",
            width: "120px",
            fixed: "left",
            dataIndex: "action",
            scopedSlots: { customRender: "action" }
          },
          {
            title: '单号',
            align: 'left',
            width: '140px',
            fixed: "left",
            dataIndex: 'orderNo'
          },
          {
            title: '发货日期',
            align: 'left',
            width: '100px',
            dataIndex: 'sendDate'
          },
          {
            title: '部门',
            align: 'left',
            width: '100px',
            dataIndex: 'deptName'
          },
          {
            title: '购货方',
            align: 'left',
            width: '180px',
            ellipsis: true,
            dataIndex: 'customName'
          },
          {
            title: '购方资信',
            align: 'left',
            width: '100px',
            dataIndex: 'customBondType',
            scopedSlots: { customRender: 'customBondType' }
          },
          {
            title: '商品名称',
            align: 'left',
            width: '150px',
            ellipsis: true,
            dataIndex: 'drugsName'
          },
          {
            title: '规格',
            align: 'left',
            width: '80px',
            dataIndex: 'drugsSpec'
          },
          {
            title: '数量',
            align: 'left',
            width: '80px',
            dataIndex: 'saleNum'
          },
          {
            title: '单价',
            align: 'left',
            width: '80px',
            dataIndex: 'salePrice'
          },
          {
            title: '发货金额',
            align: 'left',
            width: '80px',
            dataIndex: 'saleAmount'
          },
          {
            title: "返款金额",
            align: "left",
            width: "120px",
            dataIndex: "supplierRealAmount"
          },
          {
            title: "返款日期",
            align: "left",
            width: "120px",
            dataIndex: "supplierRetDate"
          },
          {
            title: '退款金额',
            align: 'left',
            needTotal: true,
            width: '80px',
            dataIndex: 'customBond'
          },
          {
            title: '多收金额',
            align: 'left',
            needTotal: true,
            width: '80px',
            dataIndex: 'customOverBond'
          }
        ],
        operator: operator
      }
    },
    created() {
    },
    methods: {
      setData() {
      },
      openMultiple(searchParams) {
        if (searchParams.deptId) {
          this.deptId = searchParams.deptId
          this.multiple = true
          this.$refs.table.openMultiple()
        } else {
          this.multiple = false
          this.$refs.table.closeMultiple()
        }
      },
      //部门切换
      deptChange(value) {
        this.queryParam.deptId = value
        this.$refs.table.refresh(false)
      },
      settleHandler(record) {
        let amount= record.customBond;
        if(record.customOverBond&&record.customOverBond!=0){
          amount+=parseFloat(record.customOverBond)
        }

        this.$refs["cbreturnDrawer"].showDrawer({
          customBond:amount,
          orderDetailsId:  record.orderDetailsId,
          deptId: record.deptId
        }, "form1")
      },
      /**
       * 查询事件
       * @param searchParams
       */
      searchTable(searchParams) {
        this.queryParam = Object.assign(this.queryParam, searchParams)
        this.$refs.table.refresh(true, searchParams)
      },
      /**
       * 刷新列表
       */
      onLoad() {
        this.$refs.table.refresh()
        this.$emit('changeTab')
      }
    }
  }
</script>
